<template>
  <div class="goods-item" @click="itemClick">
      <van-image :width="size[0]" :height="size[1]" :src="goodItemProps.thumb"/>
      
    <div id="goods-info" @click="infoClick">
      <div class="goods_name">{{ goodItemProps.desc }}</div>
      <div class=goods_row>
        <div class="goods_price">¥
          <em class="goods_price_int"> {{ goodItemProps.price }} </em>
        </div>
        <div class="old-price">{{ goodItemProps.oldPrice }} </div>
      </div>

      <div class="goods_row">
        <div class="goods-num">已售 {{ goodItemProps.selled }} 件</div>
        <div class="goods_collect">收藏 {{ goodItemProps.collect }}</div>
      </div>
      
    </div>
  </div>
</template>

<script>
import { ref, toRefs } from 'vue'
import { useRouter } from 'vue-router'
export default {
  name: "GoodItem",
  props: {
    size: {
      type: Array,
      default(){
        return [175, 175]
      }
    },
    goodItemProps: {
      type: Object,
      default: {
        goodID: 0,
        num: 2,
        selled: 10000,
        tag: "标签1",
        price:"2.00",
        desc: "描述",
        title: "商品信息",
        thumb: "https://img.yzcdn.cn/vant/ipad.jpeg",
        oldPrice: "10.00",
        collect: 0,
      }
    },
  },
  // methods: {
    
  //   imgLoad() {
  //     // 判断是哪个路由活跃用以判断是首页还是推荐页的监听事件
  //     //首页
  //     /*
  //     按理说这样应该是反的，但是这样写却又是可以正确获得
  //     */
  //     if (this.$route.path.indexOf("/home")) {
  //       this.$bus.$emit("DetailItemIamgLoad");
  //     }
  //     // 详情页
  //     else if (this.$route.path.indexOf("/detail")) {
  //       this.$bus.$emit("itemIamgLoad");
  //     }
  //     // this.$bus.$emit('itemIamgLoad')
  //   },
  // },
  setup(props) {
    const router = useRouter()
    const { goodItemProps } = toRefs(props)
    // const imgP = ref("./assets/ipad.jpeg")

    const itemClick = ()  => {
      console.log("itemClick", props.goodItemProps)
      router.push({
        path:"/detail/"+props.goodItemProps.goodID
      })
    }

    const infoClick = ()  => {
      console.log("infoClick")
    }
    return {
      goodItemProps,
      itemClick,
      infoClick
    }
  }
}
</script>


<style lang="less">

.goods-item {
  position: relative;
  padding-bottom: 6px;
  width: 48%;
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 5px;
}

#goods-info {
  padding: 0 8px 8px;
}

#goods-info .sc-img {
  position: relative;
  left: -4px;
  top: 2px;
  width: 14px;
  height: 14px;
}

.goods_name {
    text-align: left;
    height: 32px;
    font-size: 12px;
    font-family: -apple-system, Helvetica, sans-serif;
    overflow: hidden;
    color: #434343;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    word-break: break-all;
    -webkit-box-orient: vertical;
}

.goods_row {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    height: 45px;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    overflow: hidden;
    justify-content: space-between;
}

.goods_price {
    font-style: normal;
    font-family: JDZH-Regular, sans-serif;
    display: inline-block;
    font-size: 20px;
    line-height: 40px;
    color: #ff4142;
}


.goods_collect {
    max-width: 100%;
    color: #999;
    overflow: hidden;
    white-space: nowrap;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
    font-size: 12px;
}

.old-price {
  color: gainsboro;
  margin-right: 10px;
  text-decoration: line-through;
  font-size: 10px;
  margin-left: 5px;
}

.goods-num {
    max-width: 100%;
    color: #999;
    overflow: hidden;
    white-space: nowrap;
    -o-text-overflow: ellipsis;
    text-overflow: ellipsis;
    font-size: 12px;
}
</style>